$(document).ready(function(){
    $("#search-area").on('click',function(){
        $("#search-outter").show();
    });
    $("#search-go-back").on('click',function(){
        $("#search-outter").hide();
    });
    $("#search-submit").on('click',function(){
        var keywords = $("#keywords").val();
        if(keywords === ""){
            var htmlstr = '<div class="none-result">请输入作品名称或者作者的名字！</div>';
            $("#search-body").html(htmlstr);
            return false;
        }
        $params = JSON.stringify({'keywords':keywords});

        $comment_back = ajaxSynchroRequest("/api/works/search",$params);
        if($comment_back.data.length === 0){
            var htmlstr = '<div class="none-result">没有找到相关的内容哦！</div>';
            $("#search-body").html(htmlstr);
        }else{
            var data = $comment_back.data,htmlstr = '';
            for(var i=0;i<data.length;i++){
                var htmlstr = htmlstr+'<div class="search-result-outter"><div class="search-result-item" data-id="'+data[i].id+'">'+data[i].title+'</div></div>';
            }
            $("#search-body").html(htmlstr);
            
        }
        
        $(".search-result-item").on('click',function(){
            var worksid = $(this).attr('data-id');
            $("#search-outter").hide();
            window.location.href = '/works/detail?worksid='+worksid;
        });
    });
    
});